﻿// For an introduction to the Navigation template, see the following documentation:
// http://go.microsoft.com/fwlink/?LinkId=232506
(function () {
    "use strict";

    WinJS.Binding.optimizeBindingReferences = true;
    window.$ = WinJS.Utilities.query;

    var app = WinJS.Application;
    var activation = Windows.ApplicationModel.Activation;
    var nav = WinJS.Navigation;


    app.addEventListener("activated", function (args) {
        if (args.detail.kind === activation.ActivationKind.launch) {
            if (args.detail.previousExecutionState !== activation.ApplicationExecutionState.terminated) {
                // TODO: This application has been newly launched. Initialize
                // your application here.
            } else {
                //Load state
                MvvmStack.Application.state.load();
            }

            args.setPromise(WinJS.UI.processAll().then(function () {
                if (nav.location) {
                    //Navigates to saved location
                    MvvmStack.Navigation.navigateOnResume(nav.location);
                } else {
                    return nav.navigate(Application.navigator.home);
                }
            }));
        }
    });

    app.start();
})();
